package com.ltcode.auth.interfaces.converter;

import com.ltcode.auth.application.dto.LoginCommand;
import com.ltcode.auth.application.dto.LoginResult;
import com.ltcode.auth.application.dto.RegisterCommand;
import com.ltcode.auth.interfaces.request.LoginRequestDTO;
import com.ltcode.auth.interfaces.response.LoginResponseDTO;
import com.ltcode.auth.interfaces.request.RegisterRequestDTO;
import org.springframework.beans.BeanUtils;

/**
 * 认证DTO转换器
 * 
 * @author ltcode
 * @since 2024-01-01
 */
public class AuthDTOConverter {

    /**
     * 登录请求DTO转换为登录命令
     */
    public static LoginCommand toLoginCommand(LoginRequestDTO dto) {
        if (dto == null) {
            return null;
        }
        
        LoginCommand command = new LoginCommand();
        BeanUtils.copyProperties(dto, command);
        return command;
    }

    /**
     * 登录结果转换为登录响应DTO
     */
    public static LoginResponseDTO toLoginResponseDTO(LoginResult result) {
        if (result == null) {
            return null;
        }
        
        LoginResponseDTO dto = new LoginResponseDTO();
        BeanUtils.copyProperties(result, dto);
        return dto;
    }

    /**
     * 注册请求DTO转换为注册命令
     */
    public static RegisterCommand toRegisterCommand(RegisterRequestDTO dto) {
        if (dto == null) {
            return null;
        }
        
        RegisterCommand command = new RegisterCommand();
        BeanUtils.copyProperties(dto, command);
        return command;
    }
}
